/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-09-02 21:48:08
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-10-23 08:58:12
 * @FilePath: \keep_motion_api\controllers\user\relation.controller.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { Relation } = require('@/models/user');
const getRelations = async (req, res) => {
  try {
    const { follower_Name, followed_Name, pageNum, pageSize } = req.query;
    const offset = (pageNum - 1) * pageSize;
    const limit = pageSize;
    const {rows, total} = await Relation.getRelations(follower_Name, followed_Name, offset, limit);
    res.status(200).send({rows, total});
  } catch (error) {
    res.status(500).json({ message: '查询关系失败', error });
  }
}
const createRelation = async (req, res) => {
  try {
    const { follower_id, followed_id } = req.body;
    const relation = await Relation.createRelation(follower_id, followed_id);
    res.status(200).send(relation);
  } catch (error) {
    res.status(500).json({ message: '创建关注关系失败', error });
  }
}
const deleteRelation = async (req, res) => {
  try {
    const { id } = req.params;
    const relation = await Relation.deleteRelation(id);
    res.status(200).send(relation);
  } catch (error) {
    res.status(500).json({ message: '删除关注关系失败', error });
  }
}

module.exports = {
  getRelations,
  createRelation,
  deleteRelation
}
